// Package _6_从尾到头打印链表 main
// @Title _6_从尾到头打印链表
// @Description
// @Author  == 琳琳也叫王木木 ==  2022-01-12 18:23
// @Create  2022-01-12 18:23
package main

import "fmt"

//Definition for singly-linked list.
type ListNode struct {
	Val  int
	Next *ListNode
}

func main() {
	head := ListNode{
		0,
		&ListNode{
			1,
			&ListNode{
				2,
				&ListNode{
					3,
					&ListNode{
						4,
						&ListNode{
							5,
							&ListNode{
								6,
								nil,
							},
						},
					},
				},
			},
		},
	}
	fmt.Println(reversePrintArr(&head))
}

// 使用栈
func reversePrintStack(head *ListNode) []int {
	return nil
}

// 翻转链表后，遍历
func reversePrint(head *ListNode) []int {
	return nil
}

// 使用数组翻转的方式，逆序打印链表
func reversePrintArr(head *ListNode) []int {
	if head == nil {
		return nil
	}
	var ans []int
	for head != nil {
		ans = append(ans, head.Val)
		head = head.Next
	}
	for i := 0; i < len(ans)/2; i++ {
		ans[i], ans[len(ans)-1-i] = ans[len(ans)-1-i], ans[i]
	}
	return ans
}
